package com.dm.shop.mapper;

import com.dm.shop.entity.ShopCart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author MyBatisPlusGenerater-Saiya Wang
 * @since 2021-07-20
 */
@Mapper
@Repository
public interface ShopCartMapper extends BaseMapper<ShopCart> {
    @Select("select product.store as store,product_image.img_url as img_url, product.name as name," +
            "format(product.promote_price,2) as promote_price," +
            "FORMAT(product.original_price,2) as original_price,product.id as pid,shopcart_num as shopcart_num" +
            " from product, product_image, shop_cart where " +
            "shop_cart.uid = #{uid} and product.id = shop_cart.pid and product.id = product_image.pid group by product_image.pid;")
    List<Map> getShopCartInfo(int uid);

    @Delete("delete from shop_cart where uid=#{uid} and pid=#{pid}")
    boolean delShopCartById(@Param("uid") int uid, @Param("pid") int pid);

    @Delete("delete from shop_cart where uid=#{uid}")
    boolean delAllShopCart(int uid);

}
